package com.iwhalecloud.bss.kite.cucc.service.attr.linkhandler;

import com.iwhalecloud.bss.kite.common.constant.KeyConsts;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.service.attr.handler.SlbCountAttrHandler;
import com.iwhalecloud.bss.kite.listener.handler.attr.annotation.AttrHandler;
import com.iwhalecloud.bss.kite.listener.handler.attr.impl.AbstractAttrLinkageHandler;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * SLB数量联动处理类
 */
@Service
@AttrHandler(SlbCountAttrHandler.class)
public class SlbCountAttrLinkHandler extends AbstractAttrLinkageHandler<AttrData> {
    @Override
    public void handle(KiteAttr kiteAttr, KiteInst kiteInst, AttrData attrData) {

        //部署域属性联动
        KiteAttr developmentDomainAttr = kiteInst.getAttr("210003822");
        if (KiteStringUtils.isNotEmpty(kiteAttr.getValue())) {
            if (Objects.nonNull(developmentDomainAttr)) {
                developmentDomainAttr.setIsNull(KeyConsts.IFTRUE_T);
            }
        } else {
            //云主机类型
            KiteAttr cloudHostTypeattr = kiteInst.getAttr("200000111");
            if (!(Objects.nonNull(cloudHostTypeattr) && KiteStringUtils.equalsAny(cloudHostTypeattr.getValue(), "100000277", "100000276", "100000274", "100006264"))) {
                developmentDomainAttr.setIsNull(KeyConsts.IFTRUE_F);
            } else if (!(Objects.nonNull(cloudHostTypeattr) && KiteStringUtils.equals("100000277", cloudHostTypeattr.getValue()))) {
                developmentDomainAttr.setIsNull(KeyConsts.IFTRUE_T);
            }
        }


    }

    @Override
    public void handleStyle(KiteAttr kiteAttr, KiteInst kiteInst, AttrData attrData) {

    }
}
